package com.awesome.videodemo.record.record1

import android.content.Intent
import android.os.Bundle
import android.widget.Button
import android.widget.Toast
import com.awesome.common.base.mvp.BaseActivity
import com.awesome.common.constant.Constant
import com.awesome.videodemo.R
import com.awesome.videodemo.record.record1.widget.VideoCameraView
import com.awesome.videodemo.record.record1.manager.VideoRecordManager


class MainActivity : BaseActivity() {
    private var flagPlay:Boolean = false
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val camera = findViewById<VideoCameraView>(R.id.camera)
        val bt = findViewById<Button>(R.id.bt)
        val bt_play = findViewById<Button>(R.id.bt_play)
        if (!hasPermission(*Constant.WRITE_EXTERNAL_PERMISSION)) {
            requestPermission(Constant.WRITE_EXTERNAL_CODE, *Constant.WRITE_EXTERNAL_PERMISSION)
        }
        if (!hasPermission(*Constant.CAMERA_PERMISSION)) {
            requestPermission(Constant.CAMERA_CODE, *Constant.CAMERA_PERMISSION)
        }
        val videoRecordManager = VideoRecordManager(camera)
        bt.setOnClickListener {
            if(flagPlay){
                videoRecordManager.stop()
                bt.text = "开始"
                Toast.makeText(this@MainActivity,"结束",Toast.LENGTH_SHORT).show()
            }else{
                videoRecordManager.start()
                bt.text = "结束"
                Toast.makeText(this@MainActivity,"开始",Toast.LENGTH_SHORT).show()
            }
            flagPlay = !flagPlay
        }
        bt_play.setOnClickListener {
            startActivity(Intent(this@MainActivity, RecordActivity1::class.java))
        }
    }
}
